<?php
/*
 * Get information about a user.
 */

// authenticate user first
F3::call('authentication.php');
if (F3::exists('auth_error'))
{
  // authentication failed
  return;
}

// get user information
$param = array('1' => F3::get('SESSION.user_id'));
$result = DB::sql("SELECT id, email, first_name, last_name, nickname, preferences FROM user WHERE id=?", $param);
$admin = DB::sql("SELECT id from admin WHERE id=?", $param);
if(count($admin)>0):
	$admin = 1;
else:
	$admin = 0;
endif;
$response = array();
foreach ($result as $row) {
	$response['email'] = $row['email'];
	$response['first_name'] = $row['first_name'];
	$response['last_name'] = $row['last_name'];
	$response['nickname'] = $row['nickname'];
	$response['preferences'] = $row['preferences'];
	$response['admin'] = $admin;
}

header('HTTP/1.1 200');
header("Content-Type: application/json");
echo json_encode($response);

?>
